## code to prepare `regdata` dataset goes here
library(matlabr)
library(R.matlab)
x <- seq(-10,10,0.1)
y <- seq(-10,10,0.1)


# 与matlab交互
Matlab$startServer() # 启动matlab服务器，可能会较慢
# 创造与matlab交互的客户端对象，并看它的运行状态
matlab <- Matlab()
# 打开运行
isOpen <- open(matlab)
print(matlab)
# 将R中的值传到matlab中
setVariable(matlab, x = x, y = y)
# matlab中运行脚本
mtcode <- "
  x = -5:0.1:5;
y = -5:0.1:5;
[x,y] = meshgrid(x,y);
z = zeros(size(x));
[n,~] = size(x);
for i=1:n
    z(:,i) = mvnpdf([x(:,i) y(:,i)]);
end
mesh(x,y,z)
"
evaluate(matlab, mtcode)
# 将matlab中的值传到R中
data <- getVariable(matlab, c("x", "y"))
# 关闭与matlab间的连接
close(matlab)

